package com.vlin.api.client;

import com.vlin.api.client.request.ParamsProducer;
import com.vlin.token.TokenManager;

public abstract class AbstractClient implements Client {

	
	@Override
	public void setApiClient(ApiClient apiClient) {
		if(apiClient != null) {
			apiClient(apiClient);
			if(getHost() != null) {
				apiClient.setHost(getHost());
			}
			if(getAPI()!= null) {
				apiClient.setAPI(getAPI());
			}
			getTokenManager().setApiClient(apiClient);
		}
	}
	
	public abstract void apiClient(ApiClient apiClient);
	
	@Override
	public void setTokenManager(TokenManager tokenManager) {
		if(tokenManager != null) {
			tokenManager(tokenManager);
			getTokenManager().setApiClient(getApiClient());
			getTokenManager().getTokenRefresher().setParamsProduer(getParamsProducer());
		}
	}
	
	public abstract void tokenManager(TokenManager tokenMnager);
	
	@Override
	public void setHost(String host) {
		if(host != null) {
			host(host);
			getApiClient().setHost(host);
		}
	}
	
	public abstract void host(String host);
	
	@Override
	public void setParamsProducer(ParamsProducer paramsProducer) {
		paramsProducer(paramsProducer);
		getTokenManager().getTokenRefresher().setParamsProduer(paramsProducer);
		
	}
	
	public abstract void paramsProducer(ParamsProducer paramsProducer);
}
